<?php
require_once 'PHPUnit/Framework.php';
require_once 'TVB/pms/pdes/common/util/mis/MisMapping.class.php';
require_once 'TVB/pms/pdes/common/util/mis/MISException.class.php';
require_once 'TVB/pms/pdes/common/bootstrap.php';

class MisMappingTest extends PHPUnit_Framework_TestCase
{
    public $xml;
    public $mis_mapping;

    function setUp()
    {
        $programme_detail = '<?xml version="1.0" encoding="utf-8"?>
            <Programme CO_CODE="TVB" PGM_ID="800022924">
            	<TOTAL_EPI>1</TOTAL_EPI>
            	<TITLE_CHINESE>翡翠歌星賀台慶</TITLE_CHINESE>
            	<TITLE_ENGLISH>All Singers For TVB Anniversary Special 2006</TITLE_ENGLISH>
            	<PGM_OBJECTIVE>紅白兩隊強勁歌星陣容和呂方,鄭裕玲的情侶主持搭檔黎明與劉德華同台合唱表演最為經典</PGM_OBJECTIVE>
            	<PGM_DESC>2006年的翡翠歌星賀台慶,參加演出的歌星包括古巨基,何韻詩,容祖兒,張敬軒,許志安,陳小春,陳奕迅,陳慧琳,楊千嬅,Twins等.男歌手所代表的紅隊為了扳回上一年敗給女歌手隊的戰局,向女歌手所代表的白隊發出了強大的挑戰.司儀呂方率領紅隊,鄭裕玲率領白隊,各出奇招,斗歌斗嘴斗舞蹈斗唱戲,節目一開始,楊千嬅等歌星演出經典粵劇《帝女花》片段,張敬軒更加反串出演.接下來的終極舞林派對,"擊"唱真音樂,弹弹琴跳跳舞亦都十分精采.甄妮,鍾鎮濤各自代表紅白隊與歌手們表演聯唱,經典歌曲百聽不厭,倫永亮與呂方合唱《沙沙的雨》,黎明也來為紅隊助陣</PGM_DESC>
            	<PGM_DESC_EXAD>翡翠歌星賀台慶中,由情侶檔呂方,鄭裕玲擔任司儀,男女歌手分為紅白兩隊進行比賽,通過唱歌,舞蹈,粵劇等節目一決高下,最終由紅隊獲勝</PGM_DESC_EXAD>
            	<PGM_DESC_E>TEST</PGM_DESC_E>
            	<INFO_STORY>2006年</INFO_STORY>
            	<SHOOTING_LOCAL OPTIONS_ID="518">EFP (外景)</SHOOTING_LOCAL>
            	<SHOOTING_LOCAL_NAME>TEST</SHOOTING_LOCAL_NAME>
            	<SHOOTING_COUNTRY>HONG KONG</SHOOTING_COUNTRY>
            	<SHOOTING_CITY>HONG KONG</SHOOTING_CITY>
            	<CATEGORY OPTIONS_ID="20"> - Select one - </CATEGORY>
            	<SUBCATEGORY OPTIONS_ID="20"> - Select one - </SUBCATEGORY>
            	<NATURE OPTIONS_ID="526">科幻</NATURE>
            	<SERIES OPTIONS_ID="527">台慶系列</SERIES>
            	<SOURCE OPTIONS_ID="20">- Select one -</SOURCE>
            	<NOMINAL>120</NOMINAL>
            	<NETWORK_CODE>J</NETWORK_CODE>
            	<TELECAST_HISTORY>2006-11-04</TELECAST_HISTORY>
            	<GAME_DONATION>N/A</GAME_DONATION>
            	<RATING>N/A</RATING>	
            	<CREATED_AT>2009-10-13 10:10:33</CREATED_AT>
            	<MODIFIED_AT>2009-10-30 14:54:21</MODIFIED_AT>
            	<CREATED_BY ADMIN_ID="9">Jojo Zhu</CREATED_BY>
            	<MODIFIED_BY ADMIN_ID="47">TEST</MODIFIED_BY>
            	<Award AWARD_ID="9699">
            		<PIZE_WON>TEST</PIZE_WON>
            		<NOMINATED>TEST</NOMINATED>
            		<YEAR>2009</YEAR>
            		<ORGANIZATION>TEST</ORGANIZATION>
            	</Award>
                <Air_Date>
                    <TELECAST_DATE>2009-06-04</TELECAST_DATE> 
                    <AIR_TIME_HHMMSS>24:19:47</AIR_TIME_HHMMSS> 
                    <NW_CODE>J</NW_CODE> 
                </Air_Date>
            </Programme>';
        $this->xml = simplexml_load_string($programme_detail);
        $this->mis_mapping = new MisMapping;
    }

    function tearDown()
    {
        unset($this->xml);
    }

    function testSucess()
    {
        try {
            $ret = $this->mis_mapping->getMapping('programme', $this->xml);
            var_dump($ret);
        } catch (MISException $e) {
            echo 'line:'. __LINE__;
        }
    }

    function testGetUINewMappingSuccess()
    {
        $ret1 = $this->mis_mapping->getMapping('programme', $this->xml);
        $ret2 = $this->mis_mapping->getUIMapping('programme', (array) $ret1);
        //var_dump($ret2);
    }

    function testAirDate()
    {
        $obj->TELECAST_DATE = '2010-05-01';
        $obj->AIR_TIME_HHMMSS = '28:00:00';

        //$obj = (object) array();
        try {
            $datetime = $this->mis_mapping->get_air_date($obj);
            #var_dump($datetime);
        } catch (MISException $e) {
            echo 'error';
        }
    }
}
?>
